package com.aaa.ssm.service.impl;

import com.aaa.ssm.dao.ScenicDao;
import com.aaa.ssm.dao.TmScenicDao;
import com.aaa.ssm.entity.Scenic;
import com.aaa.ssm.entity.TmScenic;
import com.aaa.ssm.service.TmScenicService;
import com.aaa.ssm.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ fileName:TmScenicServiceImpl
 * @ description:
 * @ createTime:2023/4/1 15:46
 * @ version:1.0.0
 */
@Service
public class TmScenicServiceImpl implements TmScenicService {

    @Resource
    private TmScenicDao tmScenicDao;
    @Resource
    private ScenicDao scenicDao;
    @Resource
    private HttpSession session;

    /**
     * 分装格式化时间类
     * @return
     */
    private static String time(){
        //获取当前时间
        Date date = new Date();
        //实例化格式化时间类
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //format格式化时间
        String format = simpleDateFormat.format(date);
        return format;
    }

    @Override
    public PageInfo queryByParam(Page<TmScenic> page) {
        PageHelper.startPage(page.getPageNo(),page.getPageSize());
        return new PageInfo(tmScenicDao.queryByParam(page.getData()));
    }

    @Override
    public int add(TmScenic tmScenic) {
        return tmScenicDao.add(tmScenic);
    }

    @Override
    public int update(TmScenic tmScenic) {
        //获取设置的loginA值 并进行转换
        String loginA = (String) session.getAttribute("loginA");
        //设置状态调用
        tmScenic.setIsline(1);
        tmScenic.setIstodayshow(1);
        tmScenic.setShrid(loginA);//审核人
        tmScenic.setShtime(time());//审核时间
        tmScenic.setShstate("1");
        int update1 = tmScenicDao.update(tmScenic);
        //封装参数到审核
        Scenic scenic = new Scenic();
        scenic.setId(Integer.parseInt(tmScenic.getScenicid()));
        scenic.setCode(tmScenic.getCode());
        scenic.setName(tmScenic.getName());
        scenic.setScover(tmScenic.getScover());
        scenic.setThemecode(tmScenic.getThemecode());
        scenic.setSeasoncode(tmScenic.getSeasoncode());
        scenic.setJbcode(tmScenic.getJbcode());
        scenic.setYytime(tmScenic.getYytime());
        scenic.setAreacode(tmScenic.getAreacode());
        scenic.setSaddress(tmScenic.getSaddress());
        scenic.setTaddress(tmScenic.getTaddress());
        scenic.setLat(tmScenic.getLat());
        scenic.setLng(tmScenic.getLng());
        scenic.setMobile(tmScenic.getMobile());
        scenic.setPhone(tmScenic.getPhone());
        scenic.setSnav(tmScenic.getSnav());
        scenic.setSummary(tmScenic.getSummary());
        scenic.setSintroduction(tmScenic.getSintroduction());
        scenic.setStraffic(tmScenic.getStraffic());
        scenic.setSnotice(tmScenic.getSnotice());
        scenic.setSprotocol(tmScenic.getSprotocol());
        scenic.setIsline(tmScenic.getIsline());
        scenic.setWeight(tmScenic.getWeight());
        scenic.setIstodayshow(tmScenic.getIstodayshow());
        scenic.setOprice(tmScenic.getOprice());
        scenic.setDprice(tmScenic.getDprice());
        scenic.setSnums(tmScenic.getSnums());
        scenic.setOnums(tmScenic.getOnums());
        scenic.setSmap(tmScenic.getSmap());
        int update = scenicDao.update(scenic);

        return update;
    }

    @Override
    public int deleteById(String id) {
        return tmScenicDao.deleteById(id);
    }
}
